public class MyQueue {
    static class ListNode {
        public int val;
        public ListNode next;
        public ListNode prev;

        public ListNode(int val) {
            this.val = val;
        }
    }
    public ListNode first;
    public ListNode Last;
    public int usedSize = 0;
    //尾插法
    public void offer(int val) {
        ListNode tmp = new ListNode(val);
        if(Last != null) {
            Last.next = tmp;
            tmp.next = Last;
            Last = tmp;
            usedSize++;
        }else {
            first = Last = tmp;
            usedSize++;
        }
    }
    //头插法
    //删除头节点 出列
    public int poll() {
        if(first == null) {
            return -1;
        }
        int first1 = first.val;
        first = first.next;
        if(first == null) {
            Last = null;
        }else {
            first.prev = null;
        }
        usedSize--;
        return first1;
    }
    //展示头节点
    public int peek() {
        if(first == null) {
            return -1;
        }
        return first.val;
    }
    public int size() {
        return usedSize;
    }
    public Boolean isEmpty() {
        return usedSize == 0;
    }
}
